﻿using System.Collections.Generic;
using System.Linq;

namespace Roulette
{
    public class Evaluator
    {
        public IEnumerable<Option> Options { get; set; }
        public int Rounds { get; set; }

        public Evaluator()
        {
            this.Options = new VegasRouletteGame().GetOptions();
        }

        public double EvaluateFitness(IEnumerable<Outcome> outcomes)
        {
            return outcomes
                .Where(outcome => outcome.Gain > 0d)
                .Sum(outcome => outcome.Probability)
                ;
        }

        public double EvaluateFitness(IAlgorithm algorithm)
        {
            IEnumerable<Outcome> outcomes = new Outcome[] { new Outcome() };
            foreach (var round in Enumerable.Range(0, this.Rounds))
            {
                outcomes = outcomes
                    .SelectMany(outcome => algorithm.ChooseBet(outcome, this.Options).Evaluate(outcome));
            }
            return this.EvaluateFitness(outcomes);
        }
    }
}
